import { ObjectTool } from '@es-tool/core'
import { CountRes } from 'database-ql/src/result-types'
import { EmptyResponseError } from '../exception/EmptyResponseError'
import { ResponseStatusException } from '../exception/ResponseStatusException'

// noinspection JSUnusedGlobalSymbols
/**
 * CountResponse
 * count 的响应
 * @author LL
 * @date 2022-01-20 上午 10:23
 **/
export class CountResponse implements CountRes {
    public total: number
    public error?: any
    public code?: number | string
    public ok?: boolean
    public requestId?: string

    public static getTotal(res: CountResponse): number {
        if (ObjectTool.isEmpty(res)) {
            throw new EmptyResponseError()
        }
        if (res.ok) {
            return res.total
        }
        throw new ResponseStatusException<CountResponse>(res)
    }
}
